package com.tx.server.message;

import com.tx.server.controller.OrderController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 用于接收MQ消息
 */
@Component
public class MqReceiver {

    Logger logger = LoggerFactory.getLogger(MqReceiver.class);

    // 1.@RabbitListener(queues = "myQueue")

    // 2.自动创建队列
    //@RabbitListener(queuesToDeclare = @Queue("myQueue"))

    // 3.自动创建，Exchange和Queue绑定
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))
    public void process(String message) {
        logger.info("MqReceiver:{}", message);
    }
    /**
     * 数码供应商服务 接受消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "computer",
            value = @Queue("computerOrder")

    ))
    public void processComputer(String message) {
        logger.info("computer MqReceiver:{}", message);
    }
    /**
     * 水果应商服务 接受消息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myOrder"),
            key = "fruit",
            value = @Queue("fruitOrder")

    ))
    public void processFruit(String message) {
        logger.info("fruit MqReceiver:{}", message);
    }

}
